#!/usr/bin python3
# -*- coding: utf-8 -*-

def finput():
    T = int(input())
    li_n = []
    li_s = []
    for i in range(T):
        n1 = int(input())
        l1 = [int(i) for i in input().split(' ')]
        li_n.append(n1)
        li_s.append(l1)
    return li_n, li_s


def main(li_n, li_s):
    li_s0 = []
    for i, e in enumerate(li_s):
        sum_1 = 0
        li = []
        for j in e:
            if j == 1:
                sum_1 += 1
            if j not in li:
                li.append(j)
        li_s0.append(li)
        res = []
        if sum_1 >= li_n[i]:
            res = sorted(li_s0[i])[len(li_s0[i]) - li_n[i]:]
        else:
            res = sorted(li_s0[i])[len(li_s0[i]) - li_n[i]:]
        for k, ke in enumerate(res):
            print(ke, end="")

            if k < len(res) - 1:
                print(" ", end=" ")
            else:
                print()



if __name__ == "__main__":
    li_n, li_s = finput()
    main(li_n, li_s)
